var categoryDao = require("../dao/categoryDao");

exports.all = function(req, res) {
	categoryDao.all(function(err, items) {
		if (err) {
			res.send(err);
			console.log(err);
		} else {
			console.log(items);
			res.render('category_all', {
				title : '所有分类',
				"categories" : items
			});
		}
	});
};

exports.add = function(req, res) {
	res.render('category_add', {
		title : '新建分类'
	});
};

exports.addAction = function(req, res) {
	var title = categoryDao.DB_COLLECTION_CATEGORY_COL_TITLE;
	var pid = categoryDao.DB_COLLECTION_CATEGORY_COL_PID;
	var item = {
		title : req.body.title,
		pid : req.body.pid,
	};

	categoryDao.add(item, function(err, item) {
		if (err) {
			res.send(err);
			console.log(err);
		} else {
			console.log(item);
			res.redirect('/category');
		}
	});
};